package com.yky.utils;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.MMSeg;
import com.chenlb.mmseg4j.MaxWordSeg;
import com.chenlb.mmseg4j.Seg;
import com.chenlb.mmseg4j.Word;

/*
 * 分词工具类
 */
public class ComplexTool {

	public static List<String> segWords(String txt) {

		List<String> result = new ArrayList<String>();

		Seg seg = new MaxWordSeg(Dictionary.getInstance()); // 取得不同的分词具体算法
		MMSeg mmSeg = new MMSeg(new StringReader(txt), seg);
		Word word = null;

		try {
			while ((word = mmSeg.next()) != null) {
				result.add(word.toString());
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	public static void main(String[] args) throws IOException {
		Dictionary.getInstance("c:aa");

		String txt = "北京 上海";
		ComplexTool c = new ComplexTool();
		List<String> list = c.segWords(txt);
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
	}

}
